#ifndef REFUELLING_STRUCT_HH
#define REFUELLING_STRUCT_HH 1

#include <string>
#include <iostream>
#include <vector>
#include "otl8.hpp"
#include "datetime_period.hpp"

static const char*  refuelling_csv_struct_s = "SELECT REFUELLINGID, REFUELLINGDATE, TOTALAMOUNT, UNITARYCOST, PLATEID, KILOMETERS, NOTES FROM REFUELLING_CSV_STRUCT";

static const char*  refuelling_csv_struct_i = "INSERT INTO REFUELLING_CSV_STRUCT ( REFUELLINGID, REFUELLINGDATE, TOTALAMOUNT, UNITARYCOST, PLATEID, KILOMETERS, NOTES )VALUES(:f1<int>, :f2<date>, :f3<double>, :f4<double>, :f5<int>, :f6<long>, :f7<char[128]>)";

static const char* refuelling_csv_struct_c = "CREATE TABLE REFUELLING_CSV_STRUCT ( REFUELLINGID INTEGER , REFUELLINGDATE  , TOTALAMOUNT FLOAT , UNITARYCOST FLOAT , PLATEID INTEGER , KILOMETERS INTEGER , NOTES VARCHAR(128) )";


class refuelling_struct
{

public:
refuelling_struct():_refuellingId(0), _refuellingDate(boost::gregorian::not_a_date_time), _totalAmount(0), _unitaryCost(0), _plateId(0), _kilometers(0), _notes(""), _emergencySupply(0), _isFull(0) {_select=refuelling_csv_struct_s;_insert=refuelling_csv_struct_i;_create=refuelling_csv_struct_c;}

refuelling_struct(int a__refuellingId, boost::gregorian::date a__refuellingDate, float a__totalAmount, float a__unitaryCost, int a__plateId, float a__kilometers, std::string a__notes):_refuellingId(a__refuellingId) , _refuellingDate(a__refuellingDate) , _totalAmount(a__totalAmount) , _unitaryCost(a__unitaryCost) , _plateId(a__plateId) , _kilometers(a__kilometers) , _notes(a__notes) {_select=refuelling_csv_struct_s;_insert=refuelling_csv_struct_i;_create=refuelling_csv_struct_c;}

int refuellingId(){return  _refuellingId;}
void set_refuellingId(int a__refuellingId){ _refuellingId = a__refuellingId;}

boost::gregorian::date refuellingDate(){return  _refuellingDate;}
void set_refuellingDate(boost::gregorian::date a__refuellingDate){ _refuellingDate = a__refuellingDate;}

float totalAmount(){return  _totalAmount;}
void set_totalAmount(float a__totalAmount){ _totalAmount = a__totalAmount;}

float unitaryCost(){return  _unitaryCost;}
void set_unitaryCost(float a__unitaryCost){ _unitaryCost = a__unitaryCost;}

int plateId(){return  _plateId;}
void set_plateId(int a__plateId){ _plateId = a__plateId;}

float kilometers(){return  _kilometers;}
void set_kilometers(float a__kilometers){ _kilometers = a__kilometers;}

std::string notes(){return  _notes;}
void set_notes(std::string a__notes){ _notes = a__notes;}

bool full() {return _isFull;}
void set_full(int a_isFull){ _isFull = a_isFull; }

bool emergencySupply() {return _emergencySupply;}
void set_emergencySupply(int a_emergencySupply){ _emergencySupply = a_emergencySupply; }

refuelling_struct & operator=( const refuelling_struct & x)
{
	_refuellingId =  x._refuellingId;
	_refuellingDate =  x._refuellingDate;
	_totalAmount =  x._totalAmount;
	_unitaryCost =  x._unitaryCost;
	_plateId =  x._plateId;
	_kilometers =  x._kilometers;
	_notes =  x._notes;
        _isFull = x._isFull;
	_emergencySupply = x._emergencySupply;
	return *this;
}

bool operator==( const refuelling_struct & x)
{
	return 	_refuellingId ==  x._refuellingId &&
	_refuellingDate ==  x._refuellingDate &&
	_totalAmount ==  x._totalAmount &&
	_unitaryCost ==  x._unitaryCost &&
	_plateId ==  x._plateId &&
	_kilometers ==  x._kilometers &&
	_isFull == x._isFull &&
	_emergencySupply == x._emergencySupply &&
	_notes ==  x._notes;
}


friend std::istream& operator >> (std::istream& ist, refuelling_struct & t)
{
	if (!(ist >> t._refuellingId)) return ist;
	if (!(ist >> t._refuellingDate)) return ist;
	if (!(ist >> t._totalAmount)) return ist;
	if (!(ist >> t._unitaryCost)) return ist;
	if (!(ist >> t._plateId)) return ist;
	if (!(ist >> t._kilometers)) return ist;
	if(!(ist >> t._isFull)) return ist;
	if(!(ist >> t._emergencySupply)) return ist;
	if (!(ist >> t._notes)) return ist;

	return ist;
}

friend std::ostream& operator << (std::ostream& ost, refuelling_struct & t)
{
	ost << t._refuellingId << " ";
	ost << t._refuellingDate << " ";
	ost << t._totalAmount << " ";
	ost << t._unitaryCost << " ";
	ost << t._plateId << " ";
	ost << t._kilometers << " ";
	ost << t._isFull << " ";
	ost << t._emergencySupply << " ";
	ost << t._notes << " ";

	return ost;
}

/*
friend otl_stream& operator >> (otl_stream& ist, refuelling_struct & t)
{
	ist >> t._refuellingId;
	ist >> t._refuellingDate;
	ist >> t._totalAmount;
	ist >> t._unitaryCost;
	ist >> t._plateId;
	ist >> t._kilometers;
	ist >> t.buf; t._notes=(const char*)t.buf;

	return ist;
}

friend otl_stream& operator << (otl_stream& ost, refuelling_struct & t)
{
	ost << t._refuellingId ;
	ost << t._refuellingDate ;
	ost << t._totalAmount ;
	ost << t._unitaryCost ;
	ost << t._plateId ;
	ost << t._kilometers ;
        ost << t._isFull;
	ost << t._emergencySupply;
	ost << t._notes.c_str() ;

	return ost;
}
*/

std::string select_stmt() { return _select; }
std::string insert_stmt() { return _insert; }
std::string create_stmt() { return _create; }


private:

	int	_refuellingId;
	boost::gregorian::date	_refuellingDate;
	float	_totalAmount;
	float	_unitaryCost;
	int	_plateId;
	float	_kilometers;
	bool 	_isFull;
	bool 	_emergencySupply;
	std::string	_notes;
	std::string _create;
	std::string _select;
	std::string _insert;
char buf[128];
	
};
#endif
